package com.show.service.sensor;

import com.show.dao.population.PopulationRepository;
import com.show.dto.sensor.ShaftCoverSensor;
import com.show.dto.sensor.ShaftCoverSensorError;
import com.show.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 井盖传感器service
 *
 * @author 姜文
 */
@Service
public class ShaftCoverSensorErrorService {

    private QueryUtil queryUtil;

    private PopulationRepository populationRepository;

    @Autowired
    public ShaftCoverSensorErrorService(QueryUtil queryUtil, PopulationRepository populationRepository) {
        this.queryUtil = queryUtil;
        this.populationRepository = populationRepository;
    }


    /**
     * 井盖传感器故障总数
     *
     * @author 姜文
     */
    public List<ShaftCoverSensorError> shaftCoverSensorErrorTotal() {
        String sql = "SELECT * FROM `shaft_cover_sensor_error` GROUP BY shaft_cover_sensor_id";
        List<ShaftCoverSensorError> shaftCoverSensorErrorList = queryUtil.query(sql, ShaftCoverSensorError.class);
        return shaftCoverSensorErrorList;
    }

    /**
     * 井盖传感器故障
     *
     * @author 姜文
     */
    public List<ShaftCoverSensorError> shaftCoverSensorEvent() {
        String sql = "SELECT\n" +
                "\tacse.*, scs.*\n" +
                "FROM\n" +
                "\t`shaft_cover_sensor_error` acse\n" +
                "LEFT JOIN shaft_cover_sensor scs ON acse.shaft_cover_sensor_id = scs.shaft_cover_sensor_id\n" +
                "GROUP BY\n" +
                "\tacse.shaft_cover_sensor_id";
        List<ShaftCoverSensorError> shaftCoverSensorErrorList = queryUtil.query(sql, ShaftCoverSensorError.class);
        return shaftCoverSensorErrorList;
    }

    /**
     * 井盖传感器故障-大屏展示-点击事件
     *
     * @author 姜文
     */
    public List<ShaftCoverSensorError> shaftCoverSensorError() {
        String sql = "SELECT\n" +
                "\tscse.shaft_cover_sensor_error_id AS shaftCoverSensorErrorId,\n" +
                "\tscse.`status` AS status,\n" +
                "\tscse.status_name AS statusName,\n" +
                "\tcu.lng AS lon,\n" +
                "\tcu.lat AS lat\n" +
                "FROM\n" +
                "\t`shaft_cover_sensor_error` scse\n" +
                "LEFT JOIN shaft_cover_sensor scs ON scse.shaft_cover_sensor_id = scs.shaft_cover_sensor_id\n" +
                "LEFT JOIN cg_unit cu ON scs.signalQuality = cu.unit_id";
        List<ShaftCoverSensorError> shaftCoverSensorErrorList = queryUtil.query(sql, ShaftCoverSensorError.class);
        return shaftCoverSensorErrorList;
    }

    /**
     * 井盖传感器故障事件-大屏展示-点击事件
     *
     * @author 姜文
     */
    public List<ShaftCoverSensorError> shaftCoverSensorErrorEvent(String id) {
        String sql = "SELECT\n" +
                "\tscse.shaft_cover_sensor_error_id AS shaftCoverSensorErrorId,\n" +
                "\tscse.`status` AS STATUS,\n" +
                "\tscse.status_name AS statusName,\n" +
                "\tcu.lng AS lon,\n" +
                "\tcu.lat AS lat\n" +
                "FROM\n" +
                "\t`shaft_cover_sensor_error` scse\n" +
                "LEFT JOIN shaft_cover_sensor scs ON scse.shaft_cover_sensor_id = scs.shaft_cover_sensor_id\n" +
                "LEFT JOIN cg_unit cu ON scs.signalQuality = cu.unit_id\n" +
                "WHERE scse.shaft_cover_sensor_error_id = '"+id+"'";
        List<ShaftCoverSensorError> shaftCoverSensorErrorList = queryUtil.query(sql, ShaftCoverSensorError.class);
        return shaftCoverSensorErrorList;
    }


}
